package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppCommentReply;
import com.vf.admin.miaodong.entity.AppRealName;
import com.vf.admin.miaodong.entity.AppUser;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * 实名认证
 */
@Repository
public class AfterRealNameDao extends BaseDao<AppRealName> {

    /**
     * 详情
     */
    public AppRealName get(Integer id) {
        if (id==null || id<=0) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_real_name where 1=1");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppRealName.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppRealName appRealName) {
        if (appRealName!=null && appRealName.getId() != null && appRealName.getId() > 0) {
            this.update(appRealName);
        } else {
            appRealName.setId(this.add(appRealName));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id==null || id <= 0) {
            return;
        }
        String sql = "delete  from app_real_name where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    /**
     * 综合查询列表
     */
    public List<AppRealName> findList(Map<String, Object> map, SplitPageBean bean) {
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("");
        sbStr.append(" SELECT a.* FROM app_real_name a where 1=1 ");
        if (StringEx.isNotNull(map.get("nick"))) {
            sbStr.append(" and a.nick like ? ");
            paramList.add("%" + map.get("nick") + "%");
        }
        if (StringEx.isNotNull(map.get("status"))) {
            sbStr.append(" and a.status = ? ");
            paramList.add(map.get("status"));
        }
        if (StringEx.isNotNull(map.get("videostatus"))) {
            sbStr.append(" and a.shipinstate = ? ");
            paramList.add(map.get("videostatus"));
        }
        if(StringEx.isNotNull(map.get("phone"))){
            sbStr.append(" and a.phone like ? ");
            paramList.add("%"+map.get("phone")+"%");
        }
        if(StringEx.isNotNull(map.get("name"))){
            sbStr.append(" and a.name like ? ");
            paramList.add("%"+map.get("name")+"%");
        }
        if(StringEx.isNotNull(map.get("shipin"))){
            sbStr.append(" and a.shipin != '' ");
        }
        if(StringEx.isNotNull(map.get("shiming"))){
            sbStr.append(" and a.idnum != '' ");
        }
        if (!StringEx.isNull(map.get("startdate"))) {
            sbStr.append(" and a.createtime>=? ");
            paramList.add(map.get("startdate"));
        }
        if (!StringEx.isNull(map.get("enddate"))) {
            sbStr.append(" and a.createtime<=? ");
            paramList.add(map.get("enddate"));
        }
        sbStr.append(" order by a.createtime desc ");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppRealName.class, bean);
    }
}
